import library from './library.js'
import type FxLogger from '@/js/fxLogger'
import type { CreateCodeSpanFirstArg } from '@/js/fxLogger'
import type { ItemDetail } from '@/models/in-store'

interface LibraryItem {
	id: string
  handler?: Function
  label: string
  type: string
}
export default {
	id: 'out-store-order',
	label: '出库单',
	billGenerateTypeKey: 'outStoreBillGenerateType',
	actions: [{
		id: 'add',
		label: '新增',
		messageHandler (this:FxLogger, { orderData }: {orderData: CreateCodeSpanFirstArg}): string {
			return `系统单号:${this.createCodeSpan(orderData, 'OutStore')}`
		}
	}, {
		id: 'delete',
		label: '删除',
		messageHandler (this:FxLogger, { orderData }: {orderData: CreateCodeSpanFirstArg}): string {
			if (Array.isArray(orderData)) {
				return orderData.map(billData => {
					return `系统单号:${this.createCodeSpan(billData, 'OutStore')},该单据上级单据为:${billData.parentBill ? this.createCodeSpan({
						id: billData.parentBill.id,
						sysBillCode: billData.parentBill.sysBillCode
					}, billData.parentBillType as string) : '无'}`
				}).join(';')
			} else {
				return `系统单号:${this.createCodeSpan(orderData, 'OutStore')},该单据上级单据为:${orderData.parentBill ? this.createCodeSpan(orderData.parentBill, orderData.parentBill.billClass) : '无'}`
			}
		}
	}, {
		id: 'deleteMulity',
		label: '批量删除',
		messageHandler (this:FxLogger, { orderData }: {orderData: CreateCodeSpanFirstArg}): string {
			if (Array.isArray(orderData)) {
				return orderData.map(billData => {
					return `系统单号:${this.createCodeSpan(billData, 'OutStore')},该单据上级单据为:${billData.parentBill ? this.createCodeSpan({
						id: billData.parentBill.id,
						sysBillCode: billData.parentBill.sysBillCode
					}, billData.parentBillType as string) : '无'}`
				}).join(';')
			} else {
				return `系统单号:${this.createCodeSpan(orderData, 'OutStore')},该单据上级单据为:${orderData.parentBill ? this.createCodeSpan(orderData.parentBill, orderData.parentBill.billClass) : '无'}`
			}
		}
	}, {
		id: 'submit',
		label: '提交',
		messageHandler (this:FxLogger, { orderData }: {orderData: CreateCodeSpanFirstArg}): string {
			return `系统单号:${this.createCodeSpan(orderData, 'OutStore')}`
		}
	}, {
		id: 'submitMulity',
		label: '批量提交',
		messageHandler (this:FxLogger, { orderData }: {orderData: CreateCodeSpanFirstArg}): string {
			return `系统单号:${this.createCodeSpan(orderData, 'OutStore')}`
		}
	}, {
		id: 'return',
		label: '退回',
		messageHandler (this:FxLogger, { orderData }: {orderData: CreateCodeSpanFirstArg}): string {
			return `系统单号:${this.createCodeSpan(orderData, 'OutStore')}`
		}
	}, {
		id: 'returnMulity',
		label: '批量退回',
		messageHandler (this:FxLogger, { orderData }: {orderData: CreateCodeSpanFirstArg}): string {
			return `系统单号:${this.createCodeSpan(orderData, 'OutStore')}`
		}
	}, {
		id: 'check',
		label: '审核',
		messageHandler (this:FxLogger, { orderData }: {orderData: CreateCodeSpanFirstArg}): string {
			return `系统单号:${this.createCodeSpan(orderData, 'OutStore')}`
		}
	}, {
		id: 'checkMulity',
		label: '批量审核',
		messageHandler (this:FxLogger, { orderData }: {orderData: CreateCodeSpanFirstArg}): string {
			return `系统单号:${this.createCodeSpan(orderData, 'OutStore')}`
		}
	}, {
		id: 'uncheck',
		label: '反审核',
		messageHandler (this:FxLogger, { orderData }: {orderData: CreateCodeSpanFirstArg}): string {
			return `系统单号:${this.createCodeSpan(orderData, 'OutStore')}`
		}
	}, {
		id: 'uncheckMulity',
		label: '批量反审核',
		messageHandler (this:FxLogger, { orderData }: {orderData: CreateCodeSpanFirstArg}): string {
			return `系统单号:${this.createCodeSpan(orderData, 'OutStore')}`
		}
	}, {
		id: 'recheck',
		label: '复审',
		messageHandler (this: FxLogger, { orderData, opinionContent }: { orderData: CreateCodeSpanFirstArg, opinionContent: string }): string {
			if (opinionContent) {
				return `系统单号:${this.createCodeSpan(orderData, 'OutStore')};备注为${opinionContent}`
			} else {
				return `系统单号:${this.createCodeSpan(orderData, 'OutStore')}`
			}
		}
	}, {
		id: 'recheckMulity',
		label: '批量复审',
		messageHandler (this:FxLogger, { orderData }: {orderData: CreateCodeSpanFirstArg}): string {
			return `系统单号:${this.createCodeSpan(orderData, 'OutStore')}`
		}
	}, {
		id: 'unrecheck',
		label: '取消复审',
		messageHandler (this:FxLogger, { orderData }: {orderData: CreateCodeSpanFirstArg}): string {
			return `系统单号:${this.createCodeSpan(orderData, 'OutStore')}`
		}
	}, {
		id: 'unrecheckMulity',
		label: '批量取消复审',
		messageHandler (this:FxLogger, { orderData }: {orderData: CreateCodeSpanFirstArg}): string {
			return `系统单号:${this.createCodeSpan(orderData, 'OutStore')}`
		}
	}, {
		id: 'splitCheck',
		label: '分批并审核',
		messageHandler (this:FxLogger, { orderData }: {orderData: CreateCodeSpanFirstArg}): string {
			return `系统单号:${this.createCodeSpan(orderData, 'OutStore')}`
		}
	}, {
		id: 'update',
		label: '修改',
		messageHandler (this:FxLogger, { pre, cur, orderData }: {pre:ItemDetail, cur:ItemDetail, orderData: CreateCodeSpanFirstArg}): string {
			return `系统单号:${this.createCodeSpan(orderData, 'OutStore')};修改信息为:` + this.createUpdateMessageByLibrary(library.main as unknown as LibraryItem[])(pre as unknown as unknown[], cur as unknown as unknown[])
		}
	}, {
		id: 'updateDetails',
		label: '修改明细',
		messageHandler (this:FxLogger, { pre, cur, orderData, itemName }: {pre:ItemDetail, cur:ItemDetail, orderData: CreateCodeSpanFirstArg, itemName: string}) {
			return `系统单号:${this.createCodeSpan(orderData, 'OutStore')},品项名称:${itemName};修改信息为:` + this.createUpdateMessageByLibrary(library.details as unknown as LibraryItem[])(pre as unknown as unknown[], cur as unknown as unknown[])
		}
	}, {
		id: 'deleteDetails',
		label: '删除明细',
		messageHandler (this:FxLogger, { orderData, deleteItemInfo }: {orderData: CreateCodeSpanFirstArg, deleteItemInfo:string}): string {
			if (Array.isArray(orderData)) {
				return orderData.map(billData => {
					return `系统单号:${this.createCodeSpan(billData, 'OutStore')},删除明细信息:${deleteItemInfo};该单据上级单据为:${billData.parentBill ? this.createCodeSpan({
						id: billData.parentBill.id,
						sysBillCode: billData.parentBill.sysBillCode
					}, billData.parentBillType as string) : '无'}`
				}).join(';')
			} else {
				return `系统单号:${this.createCodeSpan(orderData, 'OutStore')},删除明细信息:${deleteItemInfo};该单据上级单据为:${orderData.parentBill ? this.createCodeSpan(orderData.parentBill, orderData.parentBill.billClass) : '无'}`
			}
		}
	}, {
		id: 'addDetails',
		label: '新增明细',
		messageHandler (this:FxLogger, { orderData, addItemInfo }: {orderData: CreateCodeSpanFirstArg, addItemInfo:string}): string {
			return `系统单号:${this.createCodeSpan(orderData, 'OutStore')},新增明细信息:${addItemInfo}`
		}
	}, {
		id: 'clearDetailMoney',
		label: '清空明细销售价格',
		messageHandler (this:FxLogger, { orderData }: { orderData: CreateCodeSpanFirstArg }) {
			if (Array.isArray(orderData)) {
				return orderData.map(billData => {
					return `系统单号:${this.createCodeSpan(billData, 'OutStore')},清空明细销售价格;该单据上级单据为:${billData.parentBill ? this.createCodeSpan(billData.parentBill, billData.parentBill.billClass) : '无'}`
				})
			} else {
				return `系统单号:${this.createCodeSpan(orderData, 'OutStore')},清空明细销售价格;该单据上级单据为:${orderData.parentBill ? this.createCodeSpan(orderData.parentBill, orderData.parentBill.billClass) : '无'}`
			}
		}
	}, {
		id: 'clearDetailInHouse',
		label: '清空明细入库仓库',
		messageHandler (this:FxLogger, { orderData }: { orderData: CreateCodeSpanFirstArg }) {
			if (Array.isArray(orderData)) {
				return orderData.map(billData => {
					return `系统单号:${this.createCodeSpan(billData, 'OutStore')},删除明细入库仓库;该单据上级单据为:${billData.parentBill ? this.createCodeSpan(billData.parentBill, billData.parentBill.billClass) : '无'}`
				})
			} else {
				return `系统单号:${this.createCodeSpan(orderData, 'OutStore')},删除明细入库仓库;该单据上级单据为:${orderData.parentBill ? this.createCodeSpan(orderData.parentBill, orderData.parentBill.billClass) : '无'}`
			}
		}
	}]
}
